<?php

class Gtux_Forms_Setup_Login extends Zend_Dojo_Form
{

  /**
   * Inicializo el formulario
   */
  public function init()
  {
    $this->setAction('/setup/login')
         ->setMethod('post')
         ->setAttrib('id', 'frmLogin');
         
    $this->setDecorators(array(
        'FormElements',
        array('HtmlTag', array('tag' => 'table')),
        'DijitForm'
    ));

    // creo la caja de texto del username
    $username = new Zend_Dojo_Form_Element_ValidationTextBox('username');
    $username->setAllowEmpty(false)
             ->setAttrib('id', 'txtUsername')
             ->setAutoInsertNotEmptyValidator(true)
             ->setConstraint('min', 4)
             ->setConstraint('max', 5)
             ->addErrorMessage('Usuario incorrecto')
             ->setLabel('Usuario')
             ->setOrder(1)
             ->setRequired(true)
             ->addValidator(new Zend_Validate_StringLength(4, 25))
             ->setDecorators(array(
                 'DijitElement',
                 'Description',
                 'Errors',
                 array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td')),
                 array('Label', array('tag' => 'td')),
                 array('decorator' => array('tr' => 'HtmlTag'), 'options' => array('tag' => 'tr')),
             ));
    // creo la caja de texto del password
    $password = new Zend_Dojo_Form_Element_PasswordTextBox('password');
    $password->setAllowEmpty(FALSE)
             ->setAttrib('id', 'txtPassword')
             ->setAutoInsertNotEmptyValidator(true)
             ->setConstraint('min', 4)
             ->addErrorMessage('Clave incorrecto')
             ->setLabel('Clave')
             ->setOrder(2)
             ->addValidator(new Zend_Validate_StringLength(4))
             ->setRequired(true)
             ->setDecorators(array(
                 'DijitElement',
                 'Description',
                 'Errors',
                 array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td')),
                 array('Label', array('tag' => 'td')),
                 array('decorator' => array('tr' => 'HtmlTag'), 'options' => array('tag' => 'tr')),
             ));
    // creo el hash contra CSRF
    $nocsrf = new Zend_Form_Element_Hash('token');
    $nocsrf->setSalt(get_class($this).Zend_Registry::get('salt'));
    $nocsrf->setTimeout(3600);
             
    // creo el boton de submit
    $submit = new Zend_Dojo_Form_Element_SubmitButton('enviar');
    $submit->setValue('Enviar')
           ->setAttrib('id', 'smbEnviar')
           ->setOrder(3)
           ->setDecorators(array(
             'DijitElement',
             array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td', 'colspan' => 2, 'style' => 'text-align: center')),
             array('decorator' => array('tr' => 'HtmlTag'), 'options' => array('tag' => 'tr'))
           ));       
    // añado los elementos al formulario
    $this->addElement($username)
         ->addElement($password)
         ->addElement($nocsrf)  
         ->addElement($submit);
  }

}

?>